package cn.tj.mapper;

import cn.tj.entity.Register;
import cn.tj.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    /**
     * 通过账号查找用户信息
     * @param account
     * @return
     */
    @Select("select * from user where account = #{account}")
    User findByAccount(String account);

    /**
     * 注册用户
     * @param account
     * @param password
     */
    @Insert("insert into user values (null,null,#{account},#{password},default)")
    void register(String account, String password);

    /**
     * 通过账号名在注册请求表中查询信息
     * @param account
     * @return
     */
    @Select("select * from register " +
            "where account=#{account} ")
    Register findRegisterByAccount(String account);

    /**
     * 提交注册请求到注册表
     * @param account
     * @param password
     */
    @Insert("insert into register values " +
            "(null,#{account},#{password},default )")
    void addRegister(String account, String password);

    /**
     * 编辑用户信息
     * @param user
     */
    @Update("update user set " +
            "nickname=#{nickname},email=#{email} " +
            "where id=#{id}")
    void editInfo(User user);

    /**
     * 更新密码
     * @param password
     * @param account
     */
    @Update("update user set " +
            "password=#{password} " +
            "where account=#{account}")
    void editPassword(String password,String account);

    /**
     * 更新头像
     * @param avatar
     */
    @Update("update user set " +
            "avatar=#{avatar} " +
            "where id=#{id}")
    void editAvatar(String avatar,Integer id);
}
